//
//  ViewController.swift
//  SwiftRx研究
//
//  Created by 世霖 on 2020/7/11.
//  Copyright © 2020 世霖. All rights reserved.
//

import UIKit

class RootViewController: UIViewController {

    lazy  var dataSource:[UIViewController] = {
        var dataSource:[UIViewController] = [UIViewController]()
        dataSource.append(FirstTableViewController())
        dataSource.append(ObserViewController())
        dataSource.append(ErrorShowViewController())
        dataSource.append(UIShowBtnTextFieldViewController())
        dataSource.append(ShowTableViewViewController())
        dataSource.append(RefreshShowTableViewController())
        dataSource.append(RxSwiftObjectMapperViewController())
        dataSource.append(DouBanApiViewController())
        
        return dataSource
    }()
    
    lazy var tableView:UITableView = {
        let tableView = UITableView.init(frame: .zero, style: .plain)
        
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor =  .gray
        return tableView
        
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .red
        self.view.addSubview(tableView)
        tableView.frame = self.view.frame
    }


}
 
extension RootViewController:UITableViewDelegate , UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataSource.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let string = "string"
        var cell = tableView.dequeueReusableCell(withIdentifier: string)
        if cell == nil {
            cell = UITableViewCell.init(style: .default, reuseIdentifier: string)
        }
        let vc = self.dataSource[indexPath.row]
        let vcString = "\(vc)"
        cell?.textLabel?.text = vcString
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = self.dataSource[indexPath.row]
      
            self.navigationController?.pushViewController(vc, animated: true)
        
    }
    
}
